package com.servlet3.test;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/12/2 12:36
 */
@WebServlet(urlPatterns = "/hello", initParams = {@WebInitParam(name = "name", value = "tomcat")})
public class HelloServlet extends HttpServlet {
    private static final long serialVersionUID = 3049914172056295215L;

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        super.doGet(req, resp);
        System.out.println(Thread.currentThread() + " start...");
        sayHello();
        resp.getWriter().println("hello...this is from servlet 3");
        System.out.println(Thread.currentThread() + " finish...");
    }

    public void sayHello() {
        try {
            System.out.println(Thread.currentThread() + " processing");
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
